package com.heyqing.topic.IsPowerOfTwo_0231;

/**
 * ClassName:IsPowerOfTwo
 * Package:com.heyqing.topic.IsPowerOfTwo_0231
 * Description:
 *
 * @Date:2024/9/24
 * @Author:Heyqing
 */
public class IsPowerOfTwo {
    public boolean isPowerOfTwo(int n) {
        if (n <= 0) return false;
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if ((n & 1) == 1) count++;
            if (count > 1) return false;
            n >>= 1;
        }
        return true;
    }
}
